package userwashlogic

import (
	"context"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/userwash"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserWashDescListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserWashDescListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserWashDescListLogic {
	return &UserWashDescListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserWashDescListLogic) UserWashDescList(in *rpc.UserWashDescListRequest) (*rpc.UserWashDescListResponse, error) {
	if in.Page <= 0 {
		in.Page = 1
	}
	if in.PageSize <= 0 {
		in.PageSize = 20
	}
	resp := &rpc.UserWashDescListResponse{
		Meta: &rpc.Meta{
			Page:     in.Page,
			PageSize: in.PageSize,
		},
	}

	userWashDeices, total, err := userwash.NewUserWashDescModel(l.ctx, l.svcCtx.Db).List(in.Language, in.Page, in.PageSize)
	if err != nil {
		return nil, err
	}
	resp.Meta.Total = total
	resp.List = make([]*rpc.UserWashDescData, 0, len(userWashDeices))
	for _, userWashDesc := range userWashDeices {
		data := &rpc.UserWashDescData{
			Id:          userWashDesc.ID,
			CreatedAt:   userWashDesc.CreatedAt,
			UpdatedAt:   userWashDesc.UpdatedAt,
			Status:      userWashDesc.Status,
			AccountId:   userWashDesc.AccountId,
			Language:    userWashDesc.Language,
			Description: userWashDesc.Description,
		}
		resp.List = append(resp.List, data)
	}

	return resp, nil
}
